package com.cw.demo.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * TODO
 *
 * @author chenw
 * @date 2021/1/3
 */
public class StuInvocationHandler<T> implements InvocationHandler {
    T target;

    public StuInvocationHandler(T proxy) {
        this.target = proxy;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("代理执行：" + method.getName() +" 方法");
        //类似aop，做一些其他事情
        System.out.println("前置处理");
        Object result = method.invoke(target,args);
        System.out.println("后置处理");
        return result;
    }
}
